/*
 * Car.h
 *
 * Created: 2012-05-16 10:04:29
 *  Author: Johan
 */ 
#include "PWM.h"
#include "UART.h"

#ifndef CAR_H_
#define CAR_H_

class Car {
	public:
		
		struct Delay{
			int current;
			int limit;
		};
		
		enum State {
			Starting,
			Running,
			Braking,
			Idle
		};
		
		State getState();
		
		Car(PWM p, UART u);
		void wheelForward();
		void wheelTurn(int degrees);
		void accelerate(int percent);
		void stop();
		int getSpeed();
		void setSpeed(int speed);
		void start();
		void update(int us);
		void move();
		void brake(int speed, int ms);
		
		
	private:
		
		State state;
		int wheel_forward;		// ms where wheels are pointed forward
		int ms_per_degree;	// milliseconds per degree
		int wheel_left;			// minimum ms of the wheels
		int wheel_right;			// maximum -||-
		int motor_stop;		// ms where motor is idle
		int motor_min;
		int motor_max;
		int motor_start_delay_limit;
		int motor_start_delay_current;
		int car_speed;
		int wheel_angle;
		int braking_force;
		int braking_time_limit;
		int braking_time_current;
		Delay braking_time_begin;
		Delay braking_time_idle;
		Delay braking_time;
		PWM pwm;
		UART uart;
		
		void onBraking(int ms);
		void onStarting(int ms);
		
};



#endif /* CAR_H_ */